package com.ybl.wallet.controller;

import com.ybl.wallet.entity.Transactions;
import com.ybl.wallet.service.TransactionsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/Transactions")
public class TransactionsController {

    private TransactionsService transactionsService;

    /**
     * 查询用户钱包金额变动明细
     * @param userId 用户id
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return Transactions集合
     */
    @GetMapping("/records")
    public List<Transactions> getTransactions(@RequestParam("userId") Long userId,
                                              @RequestParam(value = "startTime", required = false) Date startTime,
                                              @RequestParam(value = "endTime", required = false) Date endTime) {
        // 查询用户的钱包记录
        List<Transactions> records = transactionsService.getTransactions(userId, startTime, endTime);
        return records;
    }
}
